const TOKEN_KEY = 's_token';
const USER_ID = 'user_id';
const ENCRYPTED_OPEN_ID = 'encrypted_open_id';

export const isLogin = () => {
    return !!getToken();
};

export const getToken = () => {
    return uni.getStorageSync(TOKEN_KEY);
};

export const setToken = (token: string) => {
    uni.setStorageSync(TOKEN_KEY, token);
};

export const clearToken = () => {
    uni.removeStorageSync(TOKEN_KEY);
};

export const setUserId = (uId: number) => {
    uni.setStorageSync(USER_ID, uId);
};

export const getUserId = () => {
    return uni.getStorageSync(USER_ID);
};

export const setAnonymousOpenId = (encryptedOpenId: string) => {
    uni.setStorageSync(ENCRYPTED_OPEN_ID, encryptedOpenId);
};

export const getAnonymousOpenId = () => {
    return uni.getStorageSync(ENCRYPTED_OPEN_ID);
};

export const logout = () => {
    uni.removeStorageSync(TOKEN_KEY);

    uni.reLaunch({
        url: '/pages/login/login',
    });
};
